package com.health.commons;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Password {
	public static String getEncodedPassword(String clearTextPassword) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		md.update(clearTextPassword.getBytes());
		return new String(md.digest());
	}
	
	public static String getEncodedPassword_Hex(String clearTextPassword) {
		return MD5Encrypt.MD5Encode(clearTextPassword);
	}
	
	public static boolean testPassword_Hex(String clearTextTestPassword, String encodedActualPassword) {
		String encodedTestPassword = MD5Password.getEncodedPassword_Hex(clearTextTestPassword);
		return (encodedTestPassword.equals(encodedActualPassword));
	}
	
	public static boolean testPassword(String clearTextTestPassword, String encodedActualPassword) {
		String encodedTestPassword = MD5Password.getEncodedPassword(clearTextTestPassword);
		return (encodedTestPassword.equals(encodedActualPassword));
	}
	
	public static void main(String[] args){
		//String arg = args[0];
		
//		if(arg.equals("-e")){
//			for(int i=1;i<args.length;i++){
//				String password = args[i];
//				System.out.println(MD5Password.getEncodedPassword_Hex(password));
//			}
//			
//		}else if(arg.equals("-t")){
//			String password = args[1];
//			String encodedPassword = args[2];
//			System.out.println(MD5Password.testPassword_Hex(password, encodedPassword));
//		}
		 
		System.out.println(MD5Password.testPassword_Hex("123456", "E10ADC3949BA59ABBE56E057F20F883E"));
		
		
	}
}
